/*
 * Copyright 2011 Clean GWT
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package com.cleangwt.bootstrap.template.client;

import com.cleangwt.bootstrap.client.ui.Navbar;
import com.cleangwt.page.client.ResizePageContainer;
import com.google.gwt.dom.client.Style.Overflow;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.user.client.ui.SimpleLayoutPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * A {@link ResizePageContainer} with {@link Navbar}.
 * 
 * @author Jess
 * @version 1.0
 * @since 1.0
 */
public class NavbarFixedContainer extends ResizePageContainer {
  private DockLayoutPanel layout = new DockLayoutPanel(Unit.PX);
  private Navbar navbar = new Navbar();
  private SimpleLayoutPanel viewport;

  /**
   * Creates a navbar-resize page container with the given links.
   * 
   * @param navbarStyle the navbar's type style
   */
  public NavbarFixedContainer(String navbarStyle) {
    initWidget(layout);
    layout.addNorth(navbar, 50);
    navbar.setStyleBase(navbarStyle);
    navbar.getElement().getParentElement().getStyle().setOverflow(Overflow.VISIBLE);
  }

  @Override
  public void clearPage() {
    viewport.setWidget(null);
  }

  /**
   * Gets the layout panel.
   * 
   * @return the layout panel
   */
  protected DockLayoutPanel getLayout() {
    return layout;
  }

  /**
   * Gets the navbar.
   * 
   * @return the navbar
   */
  public Navbar getNavbar() {
    return navbar;
  }

  @Override
  protected void onLoad() {
    super.onLoad();
    if (viewport == null) {
      viewport = new SimpleLayoutPanel();
      // add viewport finally to make the layout to be able to add other
      // widget
      layout.add(viewport);
    }
  }

  @Override
  public void setContentPage(String pageName, Widget page) {
    viewport.setWidget(page);
  }

}
